<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/course_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	$con = @mysql_connect('localhost', 'root', '');
	if (!$con) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
	
	$db_selected = @mysql_select_db('studial');
	if (!$db_selected) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
?>
<title><?php ?></title>
<link rel="stylesheet" type="text/css" href="../css/global.css" />
<link rel="stylesheet" type="text/css" href="../css/loggedpages.css" />
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
	.eventinfo {
		float: left;
		width: 600px;
		margin: 1em 2em 1em 1em;
	}
	
	.eventname {
		font-size: 18px;
		font-weight: 700;
		margin-bottom: 0.3em;	
	}
	
	.eventdesc { 
		color: #888888; 
		font-size: 14px;
	}
	
	#gradetable {
		width: 720px;
		margin: 2em auto 1em auto;
		border: 1pt solid #d0d0d0;
		border-collapse: collapse;
	}
	
	#gradetable th, #gradetable td {
		border: 1pt solid #d0d0d0;
		text-align: center;
		padding: 3px;
		font-size: 14px;
	}
	
	.order { width: 50px; }
	
	.student, .filename, .time { width: 200px; }
	
	.grade { width: 70px; }
	
	.editmode { display: none; }
	
	.greenbutton { 
		width: 90px; 
		margin-top: 3em;
		margin-bottom: 1em;
	}
	
	.gradeinput {
		margin: 0 auto 0 auto;
		width: 40px;	
		text-align: right;
	}
	
	#submitbutton { 
		display: none;
		margin-top: 0;
	}
</style>
<script language="javascript" type="text/javascript">
	function editClick() {
		var n = document.getElementsByClassName('editmode').length;
		for (var i = 0; i < n; i++) {
			document.getElementsByClassName('editmode').item(i).style.display = "block";
			document.getElementsByClassName('viewmode').item(i).style.display = "none";
		}
		document.getElementById('editbutton').style.display = "none";
		document.getElementById('submitbutton').style.display = "inline-block";
	}
</script>
<!-- InstanceEndEditable -->
</head>

<body>
	<div class="header">
        <div class="innercontent">
            <img alt="Studial" class="logo" src="../images/logo.jpg" />   
            <form id="searchform" method="post" action="">
                <div id="searchblock">
                    <input id="searchfield" name="searchfield" type="text" placeholder="Tìm kiếm" />
                    <button id="searchbutton" type="submit" name="search" value="1" title="Tìm kiếm" onclick="window.location = '../unlogged/index.php'"><img id="searchicon" src="../images/searchicon.png" /></button>
                </div>           
            </form>
            <div id="rightheader">
                <a class="headerbutton" id="logout"><span id="borderleft"></span>Đăng xuất</a>
                <a class="headerbutton" id="toboard"><?php echo "Username" ?></a>
            </div>
        </div>
    </div>
    <div class="innercontent">
        <div id="leftcolumn">
            <img alt="Avatar" id="largeavatar" src="<?php echo $path = "../images/male_avatar.png"; ?>" />
        	<div id="sidenavcontainer">	
                <ul id="sidenav">
            		<li><a class="navlink" href=""><span id="boardnav">Bảng</span></a></li>
                    <li><a class="navlink" href=""><span id="eventnav">Sự kiện</span></a></li>
                    <li><a class="navlink" href=""><span id="membernav">Thành viên</span></a></li>
                    <?php if (1) echo "<li><a class=\"navlink\" href=\"\"><span id=\"gradenav\">Bảng điểm</span></a></li>"; ?>
            	</ul>
            </div>
        </div>
        <div id="contentcolumn">
        	<div id="contentcolheader">
            	<h2>Coursename</h2>
                <div id="description">Description</div>
            </div>
		<!-- InstanceBeginEditable name="maincontent" -->
        <?php
			if(isset($_POST['total']))
			{
				$listdiem = array();
				$total = $_POST['total'];
				for( $i = 0 ; $i < $total ; $i ++)
				{
					$listdiem[] = $_POST["$i"];	
				}
				
				$event_id = $_GET['id'];
				$result = mysql_query("select * from `assignment_submission` where `assignment_id` = '".$event_id."';");
				
				for( $i = 0 ; $i < $total ; $i ++)
				{
					$rows = mysql_fetch_array($result);
					$query = "update `assignment_submission` set `grade` = '".$listdiem[$i]."' where `user_id` = '".$rows['user_id']."'";
					mysql_query($query);
				}
				
			}

		//----------------------------------------------------------------
			function returndatetime($id)
			{
				$date = new DateTime($id);
				return $date->format('d/m/Y');			
			}
			
			function getasignmentname($id)
			{
				$result = mysql_query("select * from `assignments` where `id` = '".$id."';");
				$row = mysql_fetch_array($result);
				return $row['name'];					
			}
			
			function getasignmentdescription($id)
			{
				$result = mysql_query("select * from `assignments` where `id` = '".$id."';");
				$row = mysql_fetch_array($result);
				return $row['description'];					
			}
			
			function getasignmentid($id)
			{
				$result = mysql_query("select * from `assignments` where `id` = '".$id."';");
				$row = mysql_fetch_array($result);
				return $row['id'];					
			}
		
			function getasignmentdeadline($id)
			{
				$result = mysql_query("select * from `assignments` where `id` = '".$id."';");
				$row = mysql_fetch_array($result);
				return $row['finishdate'];					
			}
		//----------------------------------------------------------------
		
			$event_id = $_GET['id'];
		
		?>
			<div class="eventinfo">
                <div class="eventname"><a href="homeboard.php?id=<?php echo getasignmentid($event_id);  ?>"><?php echo getasignmentname($event_id); ?> </a></div>
                <div class="eventdesc"><?php echo getasignmentdescription($event_id); ?></div>
                <div class="eventdesc">Hạn nộp: <?php echo returndatetime(getasignmentdeadline($event_id)); ?></div>
            </div>
            <button class="greenbutton" id="editbutton" onclick="editClick();">Sửa điểm</button>
            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $event_id; ?>">
           
           <?php
			   
		   		function getusername($id)
				{
					$result = mysql_query("select * from `users` where `id` = '".$id."';");
					$row = mysql_fetch_array($result);
					$fullname = $row['lastname']." ".$row['firstname'];
					return $fullname;
				}
		   ?>
           
                <table id="gradetable">
                    <thead>
                        <tr>
                            <th class="order">STT</th>
                            <th class="student">Sinh viên</th>
                            <th class="filename">Tên tệp tin</th>
                            <th class="time">Thời gian nộp</th>
                            <th class="grade">Điểm</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
					$user_id = $_COOKIE['studialuserid'];
					
					
					
					//Tim tat ca cac bai nop cua user
					$result = mysql_query("select `assignments`.`name`, 
													`assignment_submission`.`path`, 
													`assignment_submission`.`datesubmitted`, 
													`assignment_submission`.`grade`, 
													`assignment_submission`.`user_id` 
													from `assignment_submission` inner join `assignments` 
													on `assignment_submission`.`assignment_id` = `assignments`.`id`
													 where `assignment_submission`.`assignment_id` = '".$event_id."';");
					
					$rows_num = mysql_num_rows($result);
					
					for( $i = 0 ; $i < $rows_num ; $i ++)
					{
						$rows = mysql_fetch_array($result);
						echo '<tr>';
						echo '<td class="order">'.($i+1).'</td>';
						echo '<td class="event">'.getusername($rows['user_id']).'</td>';
						echo '<td class="filename">'.$rows['path'].'</td>';
						echo '<td class="time">'.returndatetime($rows['datesubmitted']).'</td>';
						echo '<td class="grade">';
						echo '<div class="viewmode">'.$rows['grade'].'</div>';
                        echo '<div class="editmode"><input class="gradeinput" type="text" name="'.$i.'" value="'.$rows['grade'].'" /></div>';
						echo '<input type="hidden" name="total" value="'.$rows_num.'" />';
						echo '</td>';
						echo '</tr>';
					}
					
					
					?>
                    </tbody>
                </table>
            	<button class="greenbutton" id="submitbutton" type="submit" name="submit" value="1">Xác nhận</button>
        	</form>
		<!-- InstanceEndEditable -->
    	</div>
    </div>
    <div class="footer">
    	<div id="leftfooter">Studial @ 2012 - Nhóm 01</div>
        <div id="rightfooter">
			<a href="" title="Đăng ký thêm tên trường vào hệ thống">Đăng ký trường</a>
            -
            <a href="" title="Đăng ký thêm tên ngành học vào hệ thống">Đăng ký ngành</a>
        </div>
    </div>       
</body>
<!-- InstanceEnd --></html>
